/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.business.account.core.service.processor.freeze;

import info.peigen.hotpot.business.account.core.domain.account.Account;
import info.peigen.hotpot.business.account.core.domain.account.AccountFreezeLog;
import info.peigen.hotpot.business.account.core.service.processor.base.AbstractAccountServiceProcessor;
import info.peigen.hotpot.business.account.facade.enums.AccountFreezeDirection;
import info.peigen.hotpot.business.account.facade.order.freeze.FreezeAmountOrder;
import info.peigen.hotpot.common.service.base.processor.Processor;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import org.noear.solon.annotation.Component;


/**
 * <b>(FreezeAmountProcessor)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2022/5/26
 */
@SuppressWarnings("rawtypes")
@Component
public class FreezeAmountProcessor extends AbstractAccountServiceProcessor implements Processor {
    @Override
    public Integer level() {
        return 20;
    }

    @Override
    public void execute(ProcessorServiceContext serviceContext) {
        FreezeAmountOrder order   = (FreezeAmountOrder) serviceContext.getOrder();
        Account           account = (Account) serviceContext.getDomain();
        // 冻结金额
        account.freezeCapital(order.getAmount());
        // 冻结日志
        AccountFreezeLog freezeLog = AccountFreezeLog.builder()
                .accountId(order.getAccountId())
                .tradeId(order.getTradeId())
                .freezeType(order.getType())
                .direction(AccountFreezeDirection.Freeze)
                .freezeAmount(order.getAmount())
                .reason(order.getReason())
                .bopsOperatorId(order.getBopsOperatorId())
                .build();
        serviceContext.getExtend().put("freezeLog", freezeLog);
        serviceContext.getResult().setSuccessNotFee();
    }

}
